{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n"
     ]
    }
   ],
   "source": [
    "print 'hello world'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前字母 P\n",
      "当前字母 y\n",
      "当前字母 t\n"
     ]
    }
   ],
   "source": [
    "for letter in 'Python':\n",
    "    if letter == 'h':\n",
    "        break\n",
    "    print '当前字母',letter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前变量值： 10\n",
      "当前变量值： 9\n",
      "当前变量值： 8\n",
      "当前变量值： 7\n",
      "当前变量值： 6\n",
      "Good Bye\n"
     ]
    }
   ],
   "source": [
    "var = 10\n",
    "while var > 0:\n",
    "    print '当前变量值：',var\n",
    "    var = var - 1\n",
    "    if var == 5:\n",
    "        break\n",
    "print 'Good Bye'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2  是素数\n",
      "3  是素数\n",
      "5  是素数\n",
      "7  是素数\n",
      "11  是素数\n",
      "13  是素数\n",
      "17  是素数\n",
      "19  是素数\n",
      "23  是素数\n",
      "29  是素数\n",
      "31  是素数\n",
      "37  是素数\n",
      "41  是素数\n",
      "43  是素数\n",
      "47  是素数\n",
      "53  是素数\n",
      "59  是素数\n",
      "61  是素数\n",
      "67  是素数\n",
      "71  是素数\n",
      "73  是素数\n",
      "79  是素数\n",
      "83  是素数\n",
      "89  是素数\n",
      "97  是素数\n",
      "Good Bye\n"
     ]
    }
   ],
   "source": [
    "i = 2\n",
    "while i < 100:\n",
    "    j = 2\n",
    "    while j <= i/j:\n",
    "        if not(i%j):break\n",
    "        j = j + 1\n",
    "    if j > i/j: print i,' 是素数'\n",
    "    i = i+1\n",
    "print 'Good Bye'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前字母 P\n",
      "当前字母 y\n",
      "当前字母 t\n",
      "当前字母 h\n",
      "当前字母 o\n",
      "当前字母 n\n",
      "当前水果： banana\n",
      "当前水果： apple\n",
      "当前水果： mango\n",
      "Good Bye!\n"
     ]
    }
   ],
   "source": [
    "for letter in 'Python':\n",
    "    print '当前字母',letter\n",
    "    \n",
    "fruits = ['banana','apple','mango']\n",
    "for fruit in fruits:\n",
    "    print '当前水果：',fruit\n",
    "    \n",
    "print 'Good Bye!'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前水果: banana\n",
      "当前水果: apple\n",
      "当前水果: mango\n",
      "Good Bye\n"
     ]
    }
   ],
   "source": [
    "fruits = ['banana','apple','mango']\n",
    "for index in range(len(fruits)):\n",
    "    print '当前水果:',fruits[index]\n",
    "    \n",
    "print 'Good Bye'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 等于 2 * 5\n",
      "11  是一个质数\n",
      "12 等于 2 * 6\n",
      "13  是一个质数\n",
      "14 等于 2 * 7\n",
      "15 等于 3 * 5\n",
      "16 等于 2 * 8\n",
      "17  是一个质数\n",
      "18 等于 2 * 9\n",
      "19  是一个质数\n"
     ]
    }
   ],
   "source": [
    "for num in range(10,20):\n",
    "    for i in range(2,num):\n",
    "        if num%i == 0:\n",
    "            j = num/i\n",
    "            print '%d 等于 %d * %d' % (num,i,j)\n",
    "            break\n",
    "    else:\n",
    "        print num,' 是一个质数'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bcde\n",
      "abcd\n"
     ]
    }
   ],
   "source": [
    "s = 'abcdef'\n",
    "print s[1:5]\n",
    "print s[:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['aaa', '123', 'aaa', '123']\n"
     ]
    }
   ],
   "source": [
    "a = ['aaa','123']\n",
    "print a * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1548693188.1\n",
      "2019-01-29 00:33:08\n",
      "Tue Jan 29 00:33:08\n",
      "1459175064.0\n"
     ]
    }
   ],
   "source": [
    "# -*-coding:utf-8-*-\n",
    "import time\n",
    "ticks = time.time() #时间戳\n",
    "\n",
    "print ticks\n",
    "print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())\n",
    "print time.strftime('%a %b %d %H:%M:%S',time.localtime())\n",
    "\n",
    "a = \"Sat Mar 28 22:24:24 2016\"\n",
    "print time.mktime(time.strptime(a,'%a %b %d %H:%M:%S %Y'))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
